package com.module.service

import android.app.Activity
import android.content.Context
import android.content.Intent
import com.alibaba.android.arouter.facade.annotation.Route
import com.module.app.arouter.path.LauncherPath
import com.module.app.arouter.service.ILauncherService
import com.module.frame.app.AppManager
import com.module.launcher.utils.startMain
import com.module.launcher.view.MainActivity
import com.module.launcher.view.WelcomeActivity

/**
 * @author bsnl_yanxuwen
 * @date 2021/1/20 10:53
 * Description :
 * 启动页通讯
 */
@Route(path = com.module.app.arouter.path.LauncherPath.S_LAUNChHER_SERVICE)
class LauncherServiceImpl : com.module.app.arouter.service.ILauncherService {
    override fun init(context: Context) {}
    override fun startMain(context: Context) {
        context.startMain()
    }

    override fun startWelcome(context: Context) {
        try {
            val intent = Intent(context, WelcomeActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
            if (context is Activity) {
                context.overridePendingTransition(0, 0)
            }
        } catch (e: Exception) {
        }
        //除了WelcomeActivity ，其它全部移除
        AppManager.getInstance().finishAllActivity(WelcomeActivity::class.java)
    }

    override fun goMsg(context: Context) {
        context.startMain(1)
    }

    override fun goMy(context: Context) {
        context.startMain(2)
    }

    override fun isWelcomeActivity(): Boolean {
        return AppManager.getInstance().currentActivity() is WelcomeActivity
    }

    override fun getDefaultPushActivity(): Class<out Activity> {
        return MainActivity::class.java
    }
}